package cn.wiseda.finance.join;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

public class JDbcTemplateDemo {
    private JdbcTemplate jdbcTemplate;
    private DataSource dataSource;
    
    public JDbcTemplateDemo(){
        
    }

    public Portfolio getPortfolio(Integer portfolioId) {  
            jdbcTemplate = new JdbcTemplate(this.dataSource);  
            String sql = "select p.portfolio_id, p.portfolio_name, f.fund_id, f.fund_name, f.stock_price, f.quantity from portfolio p INNER join fund f ON p.portfolio_id = f.portfolio_id and p.portfolio_id ="+portfolioId;  
            RowMapper mapper = (RowMapper) new PortfolioRowMapper();  
            List traderList = jdbcTemplate.query(sql, mapper);  
            for(Object obj : traderList){  
                return (Portfolio)obj;  
            }  
            return null;  
        }  
    
}

